package com.bilibili.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.CommenResult;
import com.bilibili.entity.User;
import com.bilibili.entity.VideoCollection;
import com.bilibili.service.VideoCollectService;
import com.bilibili.service.impl.VideoCollectServiceImpl;

@WebServlet("/queryUserFavoriteVideo.do")
public class QueryUserFavoriteVideoServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json;charset=utf-8");
		String videoId=request.getParameter("videoId");//视频id
		if(((User)request.getSession().getAttribute("loginUser")) != null) {
			int user_id = ((User)request.getSession().getAttribute("loginUser")).getUserId();
			VideoCollection vc = new VideoCollection();
			vc.setUserId(user_id);
			vc.setVideoId(Integer.parseInt(videoId));
			VideoCollectService vcs = new VideoCollectServiceImpl();
			VideoCollection videoCollection = vcs.selectVideoCollect(vc);
			CommenResult cr = new CommenResult();
			if(videoCollection != null) {
				cr.setCode(200);
			}else {
				cr.setCode(409);
			}
			response.getWriter().write(cr.toJOSNString());
		}
	}
}
